package com.thinking.in.spring.dependency.lookup;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 *
 * 单一类型的依赖查找（延迟查找） ：
 *      getBeanProvider()的方式 ,ObjectFactory
 *
 *      ObjectProvider   继承了   ObjectFactory
 * @author zjiajia
 * @date 2021/12/28 22:15
 */
public class DependencyLookupDemo {

    public static void main(String[] args) {
        // 容器
        AnnotationConfigApplicationContext applicationContext =new AnnotationConfigApplicationContext();
        // 注册 配置类
        applicationContext.register(DependencyLookupDemo.class);
        // 启动容器
        applicationContext.refresh();
        // 获取bean
        getByBeanProvider(applicationContext);
        // 关闭容器
        applicationContext.close();



    }

    private static void getByBeanProvider(AnnotationConfigApplicationContext applicationContext) {

        ObjectProvider<String> objectProvider = applicationContext.getBeanProvider(String.class);

        String object = objectProvider.getObject();

        System.out.println(object);


    }

    @Bean
    public String string(){
        return "hello world";
    }


}
